#include "TextChatMessage.h"
#include <QFontMetricsF>

CTextChatMessage::CTextChatMessage()
{

}

 QSize CTextChatMessage::GetSize(void){
     m_textWidth = 24;
     QFont font("times", 24);
     QFontMetrics fm(font);
     m_spaceWid = 190;
     int nLineHeight = fm.lineSpacing();
     //int nLineHeight = fm.lineSpacing();
     int nCount = m_strContext.count("\n");
     int nMaxWidth = 0;
     if(nCount == 0) {
         nMaxWidth = fm.width(m_strContext);
         QString value = m_strContext;
         if(nMaxWidth > m_textWidth) {
             nMaxWidth = m_textWidth;
             int size = m_textWidth / fm.width(" ");
             int num = fm.width(value) / m_textWidth;

             num = ( fm.width(value) ) / m_textWidth;
             nCount += num;
             QString temp = "";
             for(int i = 0; i < num; i++) {
                 temp += value.mid(i*size, (i+1)*size) + "\n";
             }
           //  m_strContext.replace(value, temp);
         }
     } else {
         for(int i = 0; i < (nCount + 1); i++) {
             QString value = m_strContext.split("\n").at(i);
             nMaxWidth = fm.width(value) > nMaxWidth ? fm.width(value) : nMaxWidth;
             if(fm.width(value) > m_textWidth) {
                 nMaxWidth = m_textWidth;
                 int size = m_textWidth / fm.width(" ");
                 int num = fm.width(value) / m_textWidth;
                 num = ((i+num)*fm.width(" ") + fm.width(value)) / m_textWidth;
                 nCount += num;
                 QString temp = "";
                 for(int i = 0; i < num; i++) {
                     temp += value.mid(i*size, (i+1)*size) + "\n";
                 }
                // m_strContext.replace(value, temp);
             }
         }
     }
     return QSize(nMaxWidth+m_spaceWid, 60); //(nCount + 1) * nLineHeight);
 }
